import { guid } from "@/utils/index";
import {
  _cusCategoryDict,
  _cusStatusDict,
  _contractStatusDict,
  _projectNodeStatusDict
} from "@/utils/dict";

function arrayToObj(arr) {
  let obj = {};
  arr.forEach((e, i) => {
    obj[e.value] = e.text;
  });
  return obj;
}

const cusCategoryDictObj = arrayToObj(_cusCategoryDict);
const cusStatusDictObj = arrayToObj(_cusStatusDict);
const contrastStatusDictObj = arrayToObj(_contractStatusDict);
const projectNodeStatusDictObj = arrayToObj(_projectNodeStatusDict);

export default {
  getGuid: function(value) {
    return guid();
  },
  // 客户类别字典
  cusCategoryDict: function(value) {
    return cusCategoryDictObj[value];
  },
  // 客户状态
  cusStatus: function(value) {
    return cusStatusDictObj[value];
  },
  // 合同状态
  contrastStatusDict: function(value) {
    return contrastStatusDictObj[value] || "";
  },
  // 项目节点
  projectNodeStatusDict: function(value) {
    return projectNodeStatusDictObj[value] || "";
  },
  approveStatusFilter(val) {
    if (val == undefined) {
      return "未审批";
    }
    if (val === null) {
      return "未审批";
    }
    if (val === "") {
      return "";
    }
    let dict = {
      0: "审批拒绝",
      1: "审批通过",
      2: "审批退回"
    };
    return dict[val];
  }
};
